package com.tito.common.framework.util;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tito.common.api.PageInfo;
import lombok.experimental.UtilityClass;

import java.util.Map;
@UtilityClass
public class ParamConvertUtil
{
    public static <T> IPage<T> convertToPage(PageInfo<T> pageInfo)
    {
        IPage<T> page = new Page<T>();
        page.setCurrent(pageInfo.getCurrent());
        page.setSize(pageInfo.getSize());
        return  page;
    }

    public static <T> PageInfo<T> convertToPageInfo(IPage<T> page)
    {
        PageInfo<T> pageInfo = new PageInfo<T>();
        pageInfo.setCurrent(page.getCurrent());
        pageInfo.setSize(page.getSize());
        pageInfo.setRecords(page.getRecords());
        return  pageInfo;
    }

    public static PageInfo<Map<String, Object>> convertToPageInfoMap(IPage<Map<String, Object>> pageMap)
    {
        PageInfo<Map<String, Object>> pageInfo = new PageInfo<Map<String, Object>>();
        pageInfo.setCurrent(pageMap.getCurrent());
        pageInfo.setSize(pageMap.getSize());
        pageInfo.setRecords(pageMap.getRecords());
        return  pageInfo;
    }
}
